package com.itqf.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/25
 * @Time: 上午10:35
 */
@Component
public class MyRouterFilter extends ZuulFilter {

    /**
     * 类型  pre(前)  post(后)  router(路由)  error(异常)
     * @return
     */
    @Override
    public String filterType() {
        return FilterConstants.ROUTE_TYPE;
        //return "pre";
        }

    /**
     * 执行顺序
     * @return
     */
    @Override
    public int filterOrder() {
        return 1;
    }

    /**
     * 是否通过
     * @return
     */
    @Override
    public boolean shouldFilter() {

        boolean f = RequestContext.getCurrentContext().sendZuulResponse();
        System.out.println("MyRouterFilter:执行与否："+f);
        return f;
    }

    @Override
    public Object run() throws ZuulException {

        System.out.println("MyRouterFilter filter");


        return null;
    }
}
